# -*- coding: utf-8 -*-
import MySQLdb as mysql


class SQLSession :

    def __init__(self, username, password, host):
        self.password = password
        self.username = username
        self.host = host

    def db_connect (self):
        try:
            main_db = mysql.connect(
                host = self.host,
                user = self.username,
                passwd = self.password,
                db = "test"
                )
            self.db_cursor = main_db.cursor(mysql.cursors.DictCursor)
        except mysql.OperationalError:
            return False
        else:
            return True

    def void_commander (self, query):
        try:
            self.db_cursor.execute(query)
        except mysql.DatabaseError:
            print "error in db"
        else:
            print "db connection is up"

    def verbose_commander (self, query):
        try:
            self.db_cursor.execute(query)
        except mysql.DatabaseError:
            print "error in db"
            return False
        else:
            print "db connection is up"
            return True

